// use deadpool::unmanaged::Pool;
use url::Url;
use std::sync::Arc;
use ytextract::Client;
pub async fn youtube(url: Arc<Url>) -> Result<Option<YoutubeOutput>, YoutubeError> {
    let mut client = Client::new();
    let id = url.query().and_then(|s| s.split_once("=")).unwrap().1;
        match url.path() {
            "watch" => {let video = client.video(id
                .parse().unwrap()
                // .unwrap_or_else(|s| 
                //     eprintln!("error while parsing youtube id: {e}"))
                ).await?;
            Ok(Some(YoutubeOutput{ title: video.title().to_string(), duration: video.duration().as_secs()}))
            }
            _ => Ok(None)
        }
}
// #[derive(Debug)]
// pub struct youtube_parser{
//     pool: Pool<YoutubeDl>
// }
// impl youtube_parser{
//     pub async fn create_pool() -> Self {
//         Self {
//             pool: Pool::new(5)
//         }
//     }
// }
pub struct YoutubeOutput{
    pub title: String,
    pub duration: u64
}
// impl Yo pub fn new
use thiserror::Error;
#[derive(Debug, Error)]
pub enum YoutubeError{
    #[error("youtube error")]
    YoutubeError(#[from] ytextract::error::Error),
    #[error("tokio error")]
    TokioError(#[from] tokio::task::JoinError),
    // #[error("youtube error")]
    // IdError(#[from] ytextract::error::Id)
}